package com.zhangx.study.demo.mybatis;

import com.zhangx.study.demo.StudyApp;
import com.zhangx.study.demo.mybatis.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName Test
 * @Description TODO
 * @Author zhangx
 * @Date 2021/5/17 8:29
 **/
public class Test {

    void testMybatis(){
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = Resources.getResourceAsStream("");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);

        SqlSession sqlSession = sqlSessionFactory.openSession();

        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.selectById(1);

        sqlSession.commit();
        sqlSession.flushStatements();
        sqlSession.close();

    }

    public static void main(String[] args) {

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MybatisApp.class);
//        在这里也可以注册bean
//        context.registerBean();
//        System.out.println(context.getBean("myFactoryBean"));
//        System.out.println(context.getBean("myFactoryBean"));

    }
}
